package gl.android.biyiqing.adapter;

import gl.adapter.JsonArrayImageListAdapter;
import gl.common.UserManger;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;

public class JsonArrayChatImageListAdapter extends JsonArrayImageListAdapter {
	private ArrayList<HashMap<String, String>> datas;
	public JsonArrayChatImageListAdapter(Context context, String jsonArrayData,
			int[] itemLayouts, String[] from, int[] to,
			OnItemChildViewClick mOnItemChildViewClick) {
		super(context, jsonArrayData, itemLayouts, from, to, mOnItemChildViewClick);
		datas = jsonStrng2HashMap(jsonArrayData);
	}
	protected int getViewTypeByPosition(int[] mItemLayouts, int position) {
		int resource = mResource;
		if (mItemLayouts != null&&mItemLayouts.length>1) {
			resource = mItemLayouts[position % mItemLayouts.length];
			//touserid
			final String touseid = datas.get(position).get("touserid");
			if (datas!=null&&touseid!=null&&touseid.equals(UserManger.getInstance().userid)) {
				resource = mItemLayouts[0];//myself==from
			}else{
				resource = mItemLayouts[1];//other==to
			}
		}
		return resource;
	}

}
